
<%@ page import="java.util.*" %>
<%@ page import="com.db.tracker.vo.*" %>
<%@ page import="java.sql.CallableStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.text.*" %>
<%@ page import="java.io.*" %>
<%@ page import="com.db.gef.db.DBConnection" %>
<%@ page import="com.db.gef.db.DBConnectionManager" %>
<%@ page import="com.db.tracker.util.*" %>
 
<%

try {
		 session = request.getSession();
			System.out.println("user_id..main" +session.getAttribute("USER_ID"));
			
//			if(false){
			if (session.getAttribute("USER_ID") == null || !((String) session.getAttribute("SESSION_ID")).equals(session.getId())) {
				try {
					response.sendRedirect("LoginPage.jsp");
				} catch (IOException ioe) {
					ioe.printStackTrace();
				}
	
			} 
			else
			{




%>

<% String usergroupname = (String)session.getAttribute("USER_GROUP_NAME"); %>

<HTML>
<HEAD>
<link type="text/css" rel="stylesheet" href="styles/tracker_style.css">
<TITLE>List of Shell Scripts</TITLE>
<script>
function scriptL( job,server){
	document.mainPage.jobname.value=job;
	document.mainPage.servername.value=server;
	document.mainPage.editflag.value='yes';
	document.mainPage.action="addEditScript.jsp";
	document.mainPage.submit();
}

function addNewScript()
{

	
dwin = window.open("addEditScript.jsp","_self","width=840,height=665,scrollbars=yes,resizable=yes");
	
	//document.mainPage.submit();
}




function viewScript(job,server)
{
	document.mainPage.jobname.value=job;
	document.mainPage.servername.value=server;
	document.mainPage.action = "viewScript.jsp";
	//alert("job " + job);
	document.mainPage.submit();
	//dwin = window.open("viewScript.jsp","_self","width=840,height=665,scrollbars=yes,resizable=yes");
}

function valSpace(obj){
	var fs = obj.value;
		len = fs.length;
		for(i=0;len>0 && fs.indexOf(" ")==0;i++){
			fs = fs.substring(1,len-i);
		}
		if(len==i) obj.value="";
}


function trim(sString) {
   sTrimmedString = "";
   if (sString != "") {
      var iStart = 0;
      var iEnd = sString.length - 1;
      var sWhitespace = " \t\f\n\r\v";

      while (sWhitespace.indexOf(sString.charAt(iStart)) != -1) {
         iStart++;
         if (iStart > iEnd)
            break;
      }
 
      // If the string not just whitespace
      if (iStart <= iEnd) {
         while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1)
            iEnd--;
         sTrimmedString = sString.substring(iStart,++iEnd);
      }
   }
   return sTrimmedString;
}

function search()
{
	//alert("sea");
	valSpace(document.mainPage.searchdata);
	document.mainPage.searchdata.value=trim(document.mainPage.searchdata.value);
	//alert("hii" + document.mainPage.searchtag.value); 
	if(document.mainPage.searchtag.value=="All")
	{ 
		//alert("on all");
		document.mainPage.searchallflag.value='yes';
		document.mainPage.searchdata.style.backgroundColor="#D6D6D6";
		document.mainPage.action = "ShellScriptList.jsp";
		document.mainPage.submit();
	}
	else if(document.mainPage.searchdata.value =="")
	{alert("Search field cannot be empty");
	return false ;}
	else{
		//alert("on act");
	document.mainPage.action = "ShellScriptList.jsp";
	document.mainPage.searchallflag.value=''
	document.mainPage.submit();
	}
}
function showTextField(){
	var stag = document.mainPage.searchtag.value;
	if(stag=='All'){
		document.mainPage.searchdata.disabled=true;
		document.mainPage.searchdata.style.backgroundColor='#EAEAEA';
	}else{
		document.mainPage.searchdata.disabled=false;
		document.mainPage.searchdata.style.backgroundColor='';
	}
}
</script>
</HEAD>

<BODY>

<FORM name="mainPage" onsubmit="javascript: return search()" action="" method="post">
<input type="hidden" name="jobname" value=" ">
<input type="hidden" name="servername" value=" ">
<input type="hidden" name="editflag" value="">
<input type="hidden" name="searchallflag" value="yes">
 
<TABLE width ="100%" border = "0">
	<TR>
		<TD colspan="2">
			<jsp:include page="HeaderNav.jsp" flush="true" />
		</TD>
	</TR>
</table>

<table  width ="100%">

<tr><td width="60%"class="headlineblue" align="center" ><b>List of Scripts</b></td></tr>



</TABLE>
  

  <table width ="100%">

  <tr >
  <td align="left">
  <select class=bodyblue name="searchtag" onchange='javascript:showTextField()' >
  <option value="All" align="center" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- All --&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
  <option value="Job" >Job </option>
  <option value="RunsFrom" >RunsFrom </option>
<option value="FeedDirection" >FeedDirection </option>
<option value="FromSource" >FromSource</option>
<option value="RunsTo" >RunsTo</option>
<option value="InternalFilename" >InternalFilename </option>
<option value="ExternalFilename" >ExternalFilename </option>
<option value="Summary" >Summary </option>
<option value="LocalContact" >LocalContact </option>
<option value="RemoteContact" >RemoteContact </option>
<option value="DestBizArea" >DestBizArea </option>
<option value="DestBizContact" >DestBizContact </option>
<option value="ExecutedBy" >ExecutedBy </option>
<option value="ExecsAnotherScript" >ExecsAnotherScript </option>
<option value="DataCentre_CM" >DataCentre </option>
<option value="Application_CM" >Application </option>
<option value="Group_CM" >Group </option>
<option value="MemName_CM" >MemName</option>
<option value="NodeID_CM" >NodeID</option>
<option value="Owner_CM" >Owner </option>
<option value="CommandLine_CM" >CommandLine</option>
<option value="Days_CM" >Days</option>
<option value="DependenciesIN_CM" >DependenciesIN</option>
<option value="DepInNames_CM" >DependenciesIN Names</option>
<option value="DependenciesOUT_CM" >DependenciesOUT</option>
<option value="DepOutNames_CM" >DependenciesOut Names</option>
<option value="RunTime_CM" >RunTime</option>
<option value="Misc_CM" >Misc</option>
<option value="Cyclic_CM" >Cyclic</option>
<option value="Rerun_CM" >Rerun</option>
<option value="Status" >Status</option>
<option value="Username" >Username</option>
</select>


<input class=bodyblue name="searchdata" value="" disabled='false'>
 <input type="submit" class='whitebutton'  value="Search" >
 <script>showTextField();</script>
 </td>

	 

<td align="right" ><% if("Administrator".equals(usergroupname)) { %> 

<INPUT type="button" value="Add New Script" onClick="javascript:addNewScript()" 	  class='whitebutton'>
<% } %>
<br>
<a href="mainpage.jsp">Back to Main</a>
</td>
</tr>





  </table>



<% 
	String searchallflag="";
	searchallflag=(String)request.getParameter("searchallflag");
	System.out.println("sallflag"+searchallflag);
if("yes".equals(searchallflag)|| null==searchallflag) { %>


<TABLE width="100%" name="tblReqs" cellpadding="0" cellspacing="1" style="BORDER:#000000 1px solid" align='center'>
			 
			<tr BGCOLOR = "#000077">
				<td valign="top" width='10%' class=smallfonthead><B>SR No</B></td>
				<td valign="top" width='45%' class=smallfonthead><B>Script Name</B></td>
				<td valign="top" width='45%' class=smallfonthead><B>Server</B></td>
			</tr>
	
	<% 
		DBUtil dbutil = new DBUtil(getServletContext());
		ArrayList arraylist = new ArrayList();
		
		int j=0;
		arraylist = dbutil.getScriptList();
		
		int size = arraylist.size(); 	
		System.out.println("size" + size);
		for(int i=0;i<size;i++)
		{
			ScriptVO scriptvo = (ScriptVO) arraylist.get(i); %>
			<tr BGCOLOR="EFEFEF">
			<td class="smallfontst" valign="top" align="right"> <% j=i+1;out.println(j); %></td>
			<% if("Administrator".equals(usergroupname)) { %> <td class="smallfontst" valign="top" align="left"><a href="javaScript:scriptL('<%= scriptvo.getJob() %>',
			'<%= scriptvo.getRunsFrom() %>')">
			<%= scriptvo.getJob() %></a></td>

			<% } else { %>

			<td class="smallfontst" valign="top" align="left"><a href="javaScript:viewScript('<%= scriptvo.getJob() %>','<%= scriptvo.getRunsFrom() %>')">
			<%= scriptvo.getJob() %></a></td>
			<% } %>


			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getRunsFrom() %></td>
			</tr>
		<% } 
			
		//<INPUT type="button" value="Manage Users" onclick="javascript:viewScript()"   class='whitebutton'>	
		//if("Administrator".equals(usergroupname)) out.println("hiiii");	%>

</TABLE >

<% } else { 
	ArrayList arraylist = new ArrayList();
	String field ="";
	String name ="";
	//String usergroupname = (String)session.getAttribute("USER_GROUP_NAME");
	int j=0;
	field=(String)request.getParameter("searchtag");
	name=(String)request.getParameter("searchdata");
	DBUtil dbutil= new DBUtil(getServletContext());
	if("DepInNames_CM".equals(field) ||"DepOutNames_CM".equals(field)||"Username".equals(field)||"Status".equals(field)|| "Cyclic_CM".equals(field)
		|| "Rerun_CM".equals(field))
	{
		arraylist = dbutil.searchScriptDep(field,name);
	}
	else
	{
	arraylist = dbutil.searchScript(field,name);
	}

	int size = arraylist.size(); 	
	System.out.println("sizesea" + size);

 
	
	
	if(size == 0) { %> <table width='750'><tr><td align= "left" class=bodyblue><B>Sorry data not found</b></td>
	</tr> <% } 	

	

	 else { %>
	


		<TABLE width="750" name="tblReqs" cellpadding="0" cellspacing="1" style="BORDER:#000000 1px solid">
		
		<tr BGCOLOR = "#000077">
				<td valign="top" width='10%' class=smallfonthead><B>SR No</B></td>
				<td valign="top" width='30%' class=smallfonthead><B>Script Name</B></td>
				<td valign="top" width='30%' class=smallfonthead><B>Server</B></td>
				<% if(!("Job".equals(field)) && !("RunsFrom".equals(field) )) { %> <td valign="top" width='30%' class=smallfonthead><B><%=field%></B></td>
				<% } %>
			</tr>

	<%	for(int i=0;i<size;i++) 
		{

			ScriptVO scriptvo = (ScriptVO) arraylist.get(i);
		%>

		
		

		<tr BGCOLOR="EFEFEF">
			<td class="smallfontst" valign="top" align="right"> <% j=i+1;out.println(j); %></td>
			<% if("Administrator".equals(usergroupname)) { %> <td class="smallfontst" valign="top" align="left"><a href="javaScript:scriptL('<%= scriptvo.getJob() %>',
			'<%= scriptvo.getRunsFrom() %>')">
			<%= scriptvo.getJob() %></a></td>

			<% } else { %>

			<td class="smallfontst" valign="top" align="left"><a href="javaScript:viewScript('<%= scriptvo.getJob() %>','<%= scriptvo.getRunsFrom() %>')">
			<%= scriptvo.getJob() %></a></td>
			<% } %>


			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getRunsFrom() %></td>
			<% if("FeedDirection".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getFeedDirection() %></td>
			<%}
			 else if("FromSource".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getFromSource() %></td>
			<%} 
			 else if("RunsTo".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getRunsTo() %></td>
			<%} 
			 else if("InternalFilename".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getInternalFilename() %></td>
			<%} 
			 else if("ExternalFilename".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getExternalFilename() %></td>
			<%}
			 else if("Summary".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getSummary() %></td>
			<%} 
			 else if("LocalContact".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getLocalContact() %></td>
			<%} 
			 else if("RemoteContact".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getRemoteContact() %></td>
			<%} 
			 else if("DestBizArea".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getDestBizArea() %></td>
			<%} 
			 else if("DestBizContact".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getDestBizContact() %></td>
			<%} 
			 else if("ExecutedBy".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getExecutedBy() %></td>
			<%} 
			 else if("ExecsAnotherScript".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getExecsAnotherScript() %></td>
			<%} 
			 else if("DataCentre_CM".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getDataCentre_CM() %></td>
			<%} 
			 else if("Application_CM".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getApplication_CM() %></td>
			<%} 
			 else if("Group_CM".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getGroup_CM() %></td>
			<%} 
			 else if("MemName_CM".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getMemName_CM() %></td>
			<%}
			 else if("NodeID_CM".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getNodeID_CM() %></td>
			<%} 
			 else if("Owner_CM".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getOwner_CM() %></td>
			<%} 
			 else if("CommandLine_CM".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getCommandLine_CM() %></td>
			<%} 
			 else if("Days_CM".equals(field)) { 
				String days = scriptvo.getDays_CM() ;
				 days=days.substring(1); 
				 %> 
			<td class="smallfontst" valign="top" align="left" > <%= days %></td>
			<%} 
			 else if("DependenciesIN_CM".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getDependenciesIN_CM() %></td>
			<%} 
			 else if("DependenciesOUT_CM".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getDependenciesOUT_CM() %></td>
			<%} 
			 else if("RunTime_CM".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getRunTime_CM() %></td>
			<%} 
			 else if("Misc_CM".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getMisc_CM	() %></td>


			<%} 
			 
			else if("DepInNames_CM".equals(field)) { 
				//System.out.println("Depin" + scriptvo.getDepInNames_CM()); %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getDepInNames_CM() %></td>

			<%} 
			 
			else if("DepOutNames_CM".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getDepOutNames_CM() %></td>
						
			<%} 

			else if("Cyclic_CM".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getCyclic_CM() %></td>
						
			<%} 

			else if("Rerun_CM".equals(field)) { %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getRerun_CM() %></td>
						
			<%} 
			 
			else if("Status".equals(field)) { 
				//System.out.println("Depin" + scriptvo.getDepInNames_CM()); %> 
			<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getStatus() %></td>

			<%} 
				else if("Username".equals(field)) { 
				//System.out.println("Depin" + scriptvo.getDepInNames_CM()); %> 
				<td class="smallfontst" valign="top" align="left" > <%= scriptvo.getUsername() %></td>





			<%} %>











			</tr>
		<% } %>
		</table>

		
		<% } } %>










<% }
}
catch(Exception e) {
				e.printStackTrace();
		}

		%>

</FORM>
	
</BODY>

</HTML>